<template>
  <div class="dashboard-container">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="180px" class="demo-ruleForm"
             label-position="left">
      <el-row>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item label="分类名称：" prop="cat_name">
              <el-input v-model="ruleForm.cat_name" placeholder="请输入分类名称"></el-input>
            </el-form-item>
          </div>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="分类所属级别【一级】：" prop="cat_parentid">
            <div class="grid-content bg-purple">
              <el-select v-model="ruleForm.cat_parentid" filterable placeholder="分类所属级别【一级】">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="分类所属级别【二级】：" prop="cat_secondid">
            <div class="grid-content bg-purple">
              <el-select v-model="ruleForm.cat_secondid" filterable placeholder="分类所属级别【二级】">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item label="分类储存目录名称：" prop="cat_directory">
              <el-input v-model="ruleForm.cat_directory" placeholder="请输入分类储存目录名称"></el-input>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item label="SEO优化标题：" prop="cat_seoTitle">
              <el-input v-model="ruleForm.cat_seoTitle" placeholder="请输入分类SEO优化标题"></el-input>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item label="SEO优化关键词：" prop="cat_seoKeywords">
              <el-input v-model="ruleForm.cat_seoKeywords" placeholder="请输入分类SEO优化关键词"></el-input>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item label="SEO优化描述：" prop="cat_seoDescription">
              <el-input type="textarea" v-model="ruleForm.cat_seoDescription" placeholder="请输入分类SEO优化描述"></el-input>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-form-item label="分类是否开启：" prop="cat_status">
        <el-radio-group v-model="ruleForm.cat_status">
          <el-radio label="0">不开启</el-radio>
          <el-radio label="1">开启</el-radio>
          >
        </el-radio-group>
      </el-form-item>

      <el-form-item label="分类是否在前台显示：" prop="cat_isshow">
        <el-radio-group v-model="ruleForm.cat_isshow">
          <el-radio label="0">不显示</el-radio>
          <el-radio label="1">显示</el-radio>
          >
        </el-radio-group>
      </el-form-item>
      <el-row>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item label="分类排序id：" prop="cat_listorder">
              <el-input v-enter-number v-model="ruleForm.cat_listorder" placeholder="请输入分类排序id"></el-input>
            </el-form-item>
          </div>
        </el-col>
      </el-row>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

import {courseStyle, cateAdd} from "@/api/menu";
import {adminList} from "@/api/login";

export default {
  data() {
    return {
      styleContent: '',
      mainBody: '',
      title: '',
      pic: '',
      js: '',
      tId: '',
      activeName: 'first',
      editorText: '', // 双向同步的变量
      editorTextCopy: '',// content-change 事件回掉改变的对象
      dialogImageUrl: '',
      dialogVisible: false,
      ruleForm: {
        cat_name: '',
        cat_parentid: '',
        cat_secondid: '',
        cat_directory: '',
        cat_seoTitle: '',
        cat_seoKeywords: '',
        cat_seoDescription: '',
        cat_status: '',
        cat_isshow: '',
        cat_listorder: '',


        keywords: '',
        money: '',
        classMold: '',
        typology: '',
        life: '',
        desc: '',
        details: ''
      },
      rules: {
        cat_name: [
          {required: true, message: '请输入分类名称', trigger: 'blur'}
        ],
        cat_parentid: [
          {required: true, message: '请选择分类所属级别一级分类', trigger: 'change'}
        ],
        cat_secondid: [
          {required: true, message: '请选择分类所属级别二级分类', trigger: 'change'}
        ],
        cat_directory: [
          {required: true, message: '请输入分类储存目录名称', trigger: 'blur'}
        ],
        cat_seoTitle: [
          {required: true, message: '请输入分类SEO优化标题', trigger: 'blur'}
        ],
        cat_seoKeywords: [
          {required: true, message: '请输入分类SEO优化关键词', trigger: 'blur'}
        ],
        cat_seoDescription: [
          {required: true, message: '请输入分类SEO优化描述', trigger: 'blur'}
        ],
        cat_status: [
          {required: true, message: '请选择分类是否开启', trigger: 'change'}
        ],
        cat_isshow: [
          {required: true, message: '请选择分类是否在前台显示', trigger: 'change'}
        ],
        cat_listorder: [
          {required: true, message: '请输入分类排序id', trigger: 'blur'}
        ]
      },
      drawer: false,
      options: [{
        value: '1',
        label: '黄金糕'
      }, {
        value: '2',
        label: '双皮奶'
      }, {
        value: '3',
        label: '蚵仔煎'
      }, {
        value: '4',
        label: '龙须面'
      }, {
        value: '5',
        label: '北京烤鸭'
      }],
      fileList: [{
        name: 'logo.jpeg',
        url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
      }]
    }
  },
  mounted() {
    courseStyle({typeid: 'a'}).then(response => {
      console.log(response);
      this.mainBody = response.data
    });
  },
  methods: {
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    /**
     * 新增分类提交
     * @param formName
     */
    submitForm(formName) {
      this.$refs[ formName ].validate((valid) => {
        if ( valid ) {
          this.listLoading = true;
          cateAdd(this.ruleForm).then(response => {
            if ( response.code == '200' ) {
              this.listLoading = false;
              console.log(response);
              this.$message({message: response.msg, type: 'success', duration: 1000});
              this.$router.go(-1);
            }
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[ formName ].resetFields();
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 5 个课程图`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    }
  }
}
</script>

<style scoped>
/deep/ .el-drawer {
  overflow-y: scroll;
}

.table {
  margin-bottom: 20px;
}

.my /deep/ .el-radio__inner {
  width: 18px;
  height: 18px;
}

.my /deep/ .el-radio__inner::after {
  width: 6px;
  height: 6px;
}

.small-button /deep/ .el-upload-list {
  display: none;
}

.mbys-box-right /deep/ .el-button {
  margin-left: 0px !important;
  height: 100%;
  background-color: #1f2d3d;
  border-color: #1f2d3d;
  border-radius: 0px;
  white-space: inherit;
}

.mbys-box-right /deep/ .el-button span {
  display: block;
  width: 15px;
  font-weight: bold;
  line-height: 25px;
  word-wrap: break-word;
  word-break: break-all;
  position: relative;
}
</style>
<style lang="scss" scoped>
.el-icon-caret-left {
  position: absolute;
  top: 20%;
  left: -65px;
  font-size: 80px;
  color: #1f2d3d;
}

.mbys-box-right {
  position: absolute;
  top: 0px;
  right: 0px;
  height: 100%;
}

.div-button {
  width: 10%;
}

.div-button:nth-child(2) {
  margin-left: 100px;
}

.dashboard-box-auto, .dashboard-box-bottom {
  margin-top: 15px;
}

.dashboard-container ul {
  margin: 0px;
  padding: 0px;
}

.dashboard-container li {
  list-style: none;
}

.dashboard-box-right > ul {
  font-size: 0;
  width: 100%;
}

.dashboard-box-right > ul > li:nth-child(1) {
  display: block;
  width: 100%;
  margin: 0;
  border: 5px solid #cccccc;
}

.dashboard-box-right > ul > li:nth-child(2) {
  margin-left: 0;
}

.dashboard-box-right > ul > li {
  width: 22%;
  font-size: 0;
  margin-left: 4%;
  margin-top: 15px;
  border: 3px solid #cccccc;
  display: inline-block;
}

.dashboard-box-right > ul > li > img {
  width: 100%;
}

.el-checkbox.is-bordered {
  margin: 0px;
}

.el-select {
  width: 100%;
}

.dashboard-box-top {
  display: flex;
}

.dashboard-box-left {
  width: 50%;
}

.dashboard-box-right {
  width: 26%;
  margin-left: 10%;
}

.el-radio {
  &-inner {
    width: 18px;
    height: 18px;
  }
}

.dashboard {
  &-container {
    margin: 0 15px;
    padding: 30px;
    position: relative;
    background-color: #fff;
  }

  &-text {
    font-size: 16px;
  }
}
</style>
